<% layout('/layouts/default.html', {title: '派单管理', libs: ['validate']}){ %>
<div class="main-content">
	<div class="box box-main">
		<div class="box-header with-border">
			<div class="box-title">
				<i class="fa icon-note"></i> ${text(bisDispatch.isNewRecord ? '新增派单' : '编辑派单')}
			</div>
			<div class="box-tools pull-right">
				<button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i></button>
			</div>
		</div>
		<#form:form id="inputForm" model="${bisDispatch}" action="${ctx}/bis/bisDispatch/save" method="post" class="form-horizontal">
			<div class="box-body">
				<div class="form-unit">${text('基本信息')}</div>
<!--				<div class="row">-->
<!--					-->
<!--					<div class="col-xs-6">-->
<!--						<div class="form-group">-->
<!--							<label class="control-label col-sm-4" title="">-->
<!--								<span class="required hide">*</span> ${text('派单类型')}：<i class="fa icon-question hide"></i></label>-->
<!--							<div class="col-sm-8">-->
<!--								<#form:radio path="dipatchType" dictType="dipatch_type" class="form-control required" defaultValue="1"/>-->
<!--							</div>-->
<!--						</div>-->
<!--					</div>-->
<!--				</div>-->
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required">*</span> ${text('区域')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<div class="col-sm-4" style="padding-left: 0;">
									<#form:input path="city" maxlength="64" class="form-control" readonly="true"/>
									<#form:hidden path="cityId"/>
								</div>
								<div class="col-sm-4" style="padding-left: 0;">
									<#form:input path="province" maxlength="64" class="form-control" readonly="true"/>
									<#form:hidden path="provinceId"/>
								</div>
								<div class="col-sm-4" style="padding-left: 0;padding-right: 0;">
									<#form:treeselect id="area" title="选择区域"
									path="areaId" labelPath="area" url="${ctx}/sys/area/treeData" class="required"
									allowClear="true" canSelectRoot="false" canSelectParent="false" allowInput="false"
									callbackFuncName="areaTreeselectCallback"/>
								</div>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('订单号')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="id" maxlength="20" class="form-control" readonly="true"/>
								<span class="help-block">下单后自动生成</span>
							</div>
						</div>
					</div>
				</div>
				<div class="row">
					<div class="col-xs-12">
						<div class="form-group">
							<label class="control-label col-sm-2" title="">
								<span class="required">*</span> ${text('地址')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-10">
								<#form:input path="address" maxlength="255" class="form-control required"/>
							</div>
						</div>
					</div>
				</div>
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required">*</span> ${text('寄件人')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="senderName" maxlength="20" class="form-control required realName"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required">*</span> ${text('寄件人电话')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="senderPhone" maxlength="20" class="form-control required mobile"/>
							</div>
						</div>
					</div>
				</div>
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">${text('选择快递员')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-4">
								<#form:treeselect id="assignorId" title="选择快递员" path="assignorId" labelPath="assignorName" url="${ctx}/bis/bisUser/treeData" class=""
								allowClear="true" canSelectRoot="true" canSelectParent="false" allowInput="false" callbackFuncName="assignorTreeselectCallback" onChange="assignorChange()"/>
								<span class="help-block">不选择为抢单模式</span>
							</div>
							<div class="col-sm-4">
								<div class="input-group">
									<span class="input-group-addon">红包</span>
									<#form:input path="redPackets" maxlength="20" class="form-control number"/>
								</div>
								<span class="help-block">仅抢单模式填写</span>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required">*</span> ${text('取件时间')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="senderTime" readonly="true" maxlength="20" class="form-control Wdate required"
									dataFormat="datetime" onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm',isShowClear:true});"/>
							</div>
						</div>
					</div>
				</div>
				<div class="row">
					<div class="col-xs-12">
						<div class="form-group">
							<label class="control-label col-sm-2" title="">
								<span class="required hide">*</span> ${text('备注信息')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-10">
								<#form:textarea path="remarks" rows="4" maxlength="500" class="form-control"/>
							</div>
						</div>
					</div>
				</div>
			</div>
			<div class="box-footer">
				<div class="row">
					<div class="col-sm-offset-2 col-sm-10">
						<% if (hasPermi('bis:bisDispatch:edit')){ %>
							<button type="submit" class="btn btn-sm btn-primary" id="btnSubmit"><i class="fa fa-check"></i> ${text('保 存')}</button>&nbsp;
						<% } %>
						<button type="button" class="btn btn-sm btn-default" id="btnCancel" onclick="js.closeCurrentTabPage()"><i class="fa fa-reply-all"></i> ${text('关 闭')}</button>
					</div>
				</div>
			</div>
		</#form:form>
	</div>
</div>
<% } %>
<script>
$("#inputForm").validate({
	submitHandler: function(form){
		js.ajaxSubmitForm($(form), function(data){
			js.showMessage(data.message);
			if(data.result == Global.TRUE){
				js.closeCurrentTabPage(function(contentWindow){
					contentWindow.page();
				});
			}
		}, "json");
    }
});

/**
 * 选择回调方法
 * @param id  标签的id
 * @param act 动作事件：ok、clear、cancel
 * @param index layer的索引号
 * @param layero layer内容的jQuery对象
 * @param nodes 当前选择的树节点数组
 */
function areaTreeselectCallback(id, act, index, layero, nodes){
	if (act === "ok"){
		if (nodes && nodes.length > 0){
			var node = nodes[0];
			$.ajax({
				url: "${ctx}/bis/bisDispatch/getArea",
				method: "post",
				dataType: "json",
				data: {areaId: node.id},
				success: function (res) {
					var area = res.data;
					var treeNames = area.treeNames;
					var parentCodes = area.parentCodes;
					var treeNamesAry = treeNames.split("/");
					var parentCodesAry = parentCodes.split(",");
					$("#provinceId").val(parentCodesAry[1]);
					$("#cityId").val(parentCodesAry[2]);
					$("#province").val(treeNamesAry[0]);
					$("#city").val(treeNamesAry[1]);
				}
			});
		}
	}
}
$("#city,#province").click(function(){
	$("#areaButton").trigger("click");
});

$("#assignorIdName").change(function(){
	if ($(this).val() && $(this).val().length > 0){
		$("#redPackets").val("").attr("readonly", "readonly");
	} else {
		$("#redPackets").attr("readonly", "");
	}
});

</script>